﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HtmlAgilityPack;

namespace FrameworkQ.Readable
{
    public class SimpleLargeTextStrategy : ITextParserStrategy 
    {
        public bool Parse(HtmlAgilityPack.HtmlDocument document, Parser parser)
        {
            HtmlNodeCollection colParagraphs = document.DocumentNode.SelectNodes(xpath: "//p");
            
            string text = string.Empty;
            string html = string.Empty;

            HtmlNode largeParent = null;

            foreach (HtmlNode paragraph in colParagraphs)
            {
                if (text.Length < paragraph.InnerText.Length)
                {
                    text = paragraph.InnerText;
                    html = paragraph.InnerHtml;

                    largeParent = paragraph.ParentNode;
                }
            }

            parser.Html = html;
            parser.Text = text;

            return true;
        }
    }
}
